<?php
require_once 'classes/albums.php';
require_once 'classes/mySession.php';

$message = "";
$albums = array();

#CHECK SESSION TO USER ALREADY LOGGED IN
#IF NOT, REDIRECT TO LOGIN PAGE
if(!$pgSession->isUserLoggedIn()){
	$pgSession->redirect("./login.php");
}
#IF YES:
else{
	$ownerN = $pgSession->getUserId();
	if(isset($_POST["newalbum"]) && trim($_POST["newalbum"])==='1'
			&& isset($_POST["label"])){
		$a = new Album(NULL, $ownerN, $_POST["label"]);
		
		$resp = $albumUtils->saveAlbum($a);
		
		if(!$resp["status"])
			$message = $resp["message"];
	}
	$albumsResp = $albumUtils->findUserAlbums($ownerN, -1);
	if($albumsResp["status"]){
		$albums = $albumsResp["albums"];
	}
}


#	BUILD HEADER
#	CONNECT TO DATABASE
#	CHECK IF THERE IS AN ALBUM ID ON THE POST SESSION FIELD
#		IF YES, LIST PHOTOS FROM ALBUMS (PUT + BUTTON)
#		IF NOT, LIST ALL AlBUMS (PUT + BUTTON)

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="pt-BR">
<head>
	<title>PG++ :: Ferramenta de Anotação de Localização em Fotografias</title>
	<meta charset="utf-8">
	<meta name="description" content="Ferramenta de anotação de localização em coleções de fotografias pessoais.">
	<meta name="author" content="Davi Serrano e George Henrique">

	<link rel="stylesheet" href="css/reset.css">
	<link rel="stylesheet" href="css/styles.css">
	<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
</head>

<body>

	<header>
		<div class="topo">
			<a href="./"><img class="logo left" src="images/logo.png"/></a>
			<nav class="nav-topo">
				<a href="./home.php">Mapa</a>
				<a href="./album.php">Álbuns</a>
				<a href="./geoAlbum.php">Geo-Álbuns</a>
				<a href="./photo.php">Fotos</a>
				<a href="./logout.php">Logout</a>
			</nav>
			<div class="clear"></div>
		</div>
	</header>
	
	<div class="clear"></div>
	
	<section>
		<div class="conteudo">
			<div class="topo-caixa">
				<span class="titulo">Álbuns</span>
				<form method="post" action="./album.php" class="novo-album">
					<input type="text" name="label" placeHolder="Nome do novo álbum"/>
					<input type="hidden" name="newalbum" value="1" />
					<input type="submit" value="Adicionar"/>
				</form>
			</div>
			
			<div class="caixa">
				<?php foreach ($albums as $albumRow){
					$album = $albumUtils->albumFromRow($albumRow);
				?>
				<div class="imagem">
					<img style="max-width: 100%; max-height: 100%;" src="<?php echo $album->getCover();?>"/>
					<div class="degrade"><?php echo $album->getLabel();?></div>
					<a href="./photo.php?<?php echo Album::$currentAlbumForms.'='.$album->getId().'&'.Album::$currentAlbumLabelForms.'='.$album->getLabel();?>" class="opacity"></a>
				</div>
				<?php
					}
				?>
				<hr/>
				
				<!-- 
				<div class="imagem">
					<img src="thumbnail/argentina.jpg"/>
					<div class="degrade">Vilarejos da Argentina</div>
					<a href="#" class="opacity"></a>
				</div>
				
				
				<div class="navegacao">
					<a href="#" class="voltar"><< Voltar</a>
					<a href="#" class="numero">1</a>
					<a href="#" class="numero">2</a>
					<a href="#" class="numero ativo">3</a>
					<a href="#" class="numero">4</a>
					<a href="#" class="numero">5</a>
					<a href="#" class="avancar">Avançar >></a>
					<div class="clear"></div>
				</div> -->
				
				<div class="clear"></div>
			</div>
			
			<div class="clear"></div>
		</div>
	</section>
	
	<div class="clear"></div>
	
	<footer>
		<nav class="rodape">
			<a href="#">SOBRE</a>
			<a href="#">CONTATO</a>
		</nav>
	</footer>
	
</body>
</html>
